﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace WPFHelpers
{
    /// <summary>
    /// Small convenience class for checking regex
    /// </summary>
    public static class RegexHelper
    {      
        /// <summary>
        /// Checks whether a string matches the regular expression without matching case and whole word
        /// </summary>
        /// <param name="content">String to check</param>
        /// <returns></returns>
        public static bool IsValid(string content, string pattern)
        {
            return IsValid(content, pattern, false, false);
        }

        /// <summary>
        /// Checks whether a string matches the regular expression without matching whole word
        /// </summary>
        /// <param name="content">String to check</param>
        /// <param name="matchCase">If true cases have to match</param>
        /// <returns></returns>
        public static bool IsValid(string content, string pattern, bool matchCase)
        {
            return IsValid(content, pattern, matchCase, false);
        }

        /// <summary>
        /// / Checks whether a string matches the regular expression
        /// </summary>
        /// <param name="content">String to check</param>
        /// <param name="matchCase">If true cases have to match</param>
        /// <param name="matchWholeWord">If true the whole word has to match</param>
        /// <returns></returns>
        public static bool IsValid(string content, string pattern, bool matchCase, bool matchWholeWord)
        {
            if (matchWholeWord)
            {
                return Regex.Match(content, pattern, matchCase ? RegexOptions.None : RegexOptions.IgnoreCase).Length == content.Length;
            }
            else
            {
                return Regex.IsMatch(content, pattern, matchCase ? RegexOptions.None : RegexOptions.IgnoreCase);
            }
        }       
    }
}
